class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0,right = 0,sum = 0;
        int n = nums.length;
        int count = Integer.MAX_VALUE;
        for(;right < n;right++) {
            sum += nums[right];
            while(sum >= target) {
                count = Math.min(count,right - left + 1);
                sum -= nums[left++];
            }
        }
        if(count == Integer.MAX_VALUE) return 0;
        return count;
    }
}